package org.springblade.message.params;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 消息详情表实体类
 *
 * @author weikun
 * @since 2021-05-08
 */
@Data
@ApiModel(value = "Message接收参数", description = "Message接收参数")
public class MessageParams {

	private static final long serialVersionUID = 1L;

	/**
	 * 标题
	 */
	@NotNull(message="标题不能为空")
	@ApiModelProperty(value = "标题")
	private String title;

	/**
	 * 内容
	 */
	@NotNull(message="内容不能为空")
	@ApiModelProperty(value = "内容")
	private String content;

	/**
	 * 类型  1 普通消息   2 群发消息  4 群发且包含下级 5 多发
	 */
	@NotNull(message="类型不能为空")
	@ApiModelProperty("类型")
	private Integer type;

	/**
	 * 接收人id
	 */
	@ApiModelProperty(value = "接收人id")
	private Long receiveUser;

	/**
	 * 接收人id集合
	 */
	@ApiModelProperty(value = "接收人id集合")
	private List<Long> receiveIdList;

	/**
	 * 接收群id列表
	 */
	@ApiModelProperty(value = "接收群id列表")
	private List<Long> receiveGroupList;

	public MessageParams(){}


	public static Builder builder() {
		return new Builder();
	}

	private MessageParams(Builder builder) {
		this.title = builder.title;
		this.content = builder.content;
		this.type = builder.type;
		this.receiveUser = builder.receiveUser;
		this.receiveGroupList = builder.receiveGroupList;
	}

	public static class Builder {
		private String title;
		private String content;
		private Integer type;
		private Long receiveUser;
		private List<Long> receiveIdList;
		private List<Long> receiveGroupList;


		public Builder title(String title) {
			this.title = title;
			return this;
		}
		public Builder content(String content) {
			this.content = content;
			return this;
		}
		public Builder type(Integer type) {
			this.type = type;
			return this;
		}
		public Builder receiveUser(Long receiveUser) {
			this.receiveUser = receiveUser;
			return this;
		}

		public Builder receiveIdList(List<Long> receiveIdList){
			this.receiveIdList = receiveIdList;
			return this;
		}

		public Builder receiveGroupList(List<Long> receiveGroupList) {
			this.receiveGroupList = receiveGroupList;
			return this;
		}

		public MessageParams build() {
			if (type==null) {
				throw new IllegalArgumentException("type不能为空");
			}
			if (StringUtils.isEmpty(content)) {
				throw new IllegalArgumentException("content不能为空");
			}
			if (StringUtils.isEmpty(title)) {
				throw new IllegalArgumentException("title不能为空");
			}
			if (receiveUser==null) {
				if((receiveGroupList==null||receiveGroupList.size()==0)
				&&(receiveIdList==null||receiveIdList.size()==0)){
					throw new IllegalArgumentException("接收人和接收部门不能同时为空");
				}
			}
			return new MessageParams(this);
		}
	}

}
